package view.panel.item
{
	import flash.text.TextField;
	
	import utils.ColorTool;
	import utils.TextTool;
	
	import view.components.ImgButton;
	
	public class ItemButton extends ImgButton
	{
		private var countText:TextField;
		private var _count:int;
		
		public function ItemButton(x:int, y:int, id:int, onClickFunction:Function, width:int, height:int, bg:String, face:String, text:String=null, fontSize:int=12, fontColor:uint=0xFFFFFF, bold:Boolean=true)
		{
			super(x, y, id, onClickFunction, width, height, bg, face, text, fontSize, fontColor, bold);
			initCountText();
		}
		
		private function initCountText():void
		{
			countText = TextTool.getTextField(this.width,14,10,0xFFFFFF,false,false,"right");
			
			ColorTool.glowRing(countText);
			
			countText.y = this.height - 14;
			countText.text="0";
			addChild(countText);
		}
		
		public function set count(v:int):void
		{
			if (v <= 0)
			{
				ColorTool.desaturation(_face);			
			}
			else
			{
				ColorTool.saturation(_face);
			}
			_count = v;
			countText.text = v.toString();
		}
		
		public function get count():int
		{
			return _count;
		}
		
		override public function destroy() : void
		{
			super.destroy();
			countText = null;
		}
	}
}